package overload;

/**
 * @Author Stringzhua
 * @Date 2024/2/28 20:55
 * description:
 * 允许同一个类中,多个同名方法的存在,但要求形参列表不一致
 * 方法重载,减轻了起名的麻烦,减轻了记名的麻烦
 */
public class overload01 {
    /*
     * 求和
     * 案例:类:MyCalculator 方法:calculate
     * calculate(int n1,int n2)
     * calculate(int n1,double n2)
     * calculate(double n1,int n2)
     * calculate(int n1,int n2,int n3)
     * */
    public static void main(String[] args) {
//        System.out.println(100);
//        System.out.println("helloworld");
//        System.out.println('h');
//        System.out.println(1.1);
//        System.out.println(true);
        MyCalculator mc = new MyCalculator();
        //方法重载使用时会进行匹配
        System.out.println(mc.calculate(1,2));
        System.out.println(mc.calculate(1.1,2));
    }
}

class MyCalculator {
    //两个整数的和
    public int calculate(int n1, int n2) {
        return n1 + n2;
    }
    public double calculate(int n1, double n2) {
        return n1 + n2;
    }

    public double calculate(double n1, int n2) {
        System.out.println("calculate(double n1, int n2)");
        return n1 + n2;
    }

    public int calculate(int n1, int n2, int n3) {
        return n1 + n2 + n3;
    }
}
